﻿using System.Collections.Generic;
using System.Web.Mvc;
using WebSite.ViewModels.Fields;
using WebSite.ViewModels.ViewModelExtensions.EditViewModelExtensions;

namespace WebSite.ViewModels.EditViewModels
{
    public abstract class EditViewModel : CRUDViewModel
    {
        protected EditViewModel(string title, string message = null)
            : base(title, message)
        {
        }

        public IEditViewModelExtension[] EditViewModelExtensions { get; set; }

        public TabsViewModel GetTabsViewModel(HtmlHelper htmlHelper)
        {
            return new TabsViewModel(htmlHelper, ControllerName).AddRange(GetTabs(htmlHelper));
        }

        protected virtual IEnumerable<TabItem> GetTabs(HtmlHelper htmlHelper)
        {
            yield return new TabItem("Geral", "~/Content/information.png", 
                new FormLayoutViewModel(htmlHelper).AddFieldRange(GetGeralFields()).Render(2, 10));
        }

        protected virtual IEnumerable<IField> GetGeralFields()
        {
            List<IField> result = new List<IField>();
            
            foreach (IEditViewModelExtension editViewModelExtension in EditViewModelExtensions)
            {
                result.AddRange(editViewModelExtension.GetGeralAdditionalFields(Model));
            }

            return result;
        }
    }
}